import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

export default new Vuex.Store({
    state: {
        judeg: false, //判断是三步骤还是五步骤(废置中)
        type: '', //是自然人还是企业
        data: {}, //步骤一中身份证信息
        datas: {}, //步骤一中营业执照信息
        storeDatas: {}, //步骤二中的信息
        stateJdg: false, //判断是否是修改业务
        storeId: '', //修改业务中需要用于查询的条件
        alterData: {}, //获取的用于修改的原始数据
        topBusState: '/business/allBusiness', // 业务中心顶部状态
        allBusState: '/business/allBusiness/register?id=1', // 业务中心侧边状态
        myBusState: '/business/myBusiness/auditing', // 我的业务侧边状态
        phoneNumber: '', // 用户手机号
        userId: '', // 用户ID
        userName: '', // 用户名称
        finishStatus: 0, // 是否完善信息 0为未完善,1为完善
        flat: 0, // 是否设置密码 0为未设置 1为设置,
        picType: 0, //注册后有个pictype存储证明类型
        id_card_info: {}, //用户身份证识别后信息
        company_card_info: {}, //营业执照识别后信息
        returnData: [],
    },
    mutations: {
        //判断是三步骤还是五步骤(废置中)
        fun(store) {
            store.judeg = true
        },
        //判断是三步骤还是五步骤(废置中)
        funs(store) {
            store.judeg = false
        },
        //判断是否是修改业务
        setStateJeg(store, val) {

            store.stateJdg = val
        },
        //修改业务中需要用于查询的条件
        setStoreId(store, val) {
            store.storeId = JSON.parse(JSON.stringify(val))
        },
        //获取的用于修改的原始数据
        setAltData(store, val) {
            store.alterData = JSON.parse(JSON.stringify(val))
        },
        //是自然人还是企业
        type(store, val) {
            store.type = val
        },
        //步骤一中身份证信息
        setData(store, val) {
            store.data = JSON.parse(JSON.stringify(val))
        },
        //步骤一中营业执照信息
        setDatas(store, val) {
            store.datas = JSON.parse(JSON.stringify(val))
        },
        //步骤二中的信息
        storeDatas(store, val) {

            store.storeDatas = JSON.parse(JSON.stringify(val))
        },
        // 切换业务中心顶部状态
        changeTopState(state, path) {
            state.topBusState = path;
        },
        // 切换业务中心侧边状态
        changeAllBusState(state, path) {
            state.allBusState = path;
        },
        // 切换我的业务侧边状态
        changeMyBusState(state, path) {
            console.log(path)
            state.myBusState = path;
        },
        // 设置手机号、用户id、用户名
        setPhoneNumber(state, number) {
            state.phoneNumber = number;
        },
        setUserId(state, userid) {
            state.userId = userid;
        },
        setUserName(state, name) {
            state.userName = name;
        },
        // 设置用户信息完善状态++
        setFinishStatus(state, bool) {
            state.finishStatus = bool
        },
        setFlat(state, val) {
            state.flat = val
        },
        // 重置vuex中的数据
        resetState(state) {
            this.replaceState(Object.assign({}, JSON.parse(sessionStorage.getItem('originStore'))))
        },

        //用户身份证识别后信息
        setIdCardInfo(state, val) {
            state.id_card_info = val
        },
        //营业执照识别后信息
        setCompanyCardInfo(state, val) {
            state.company_card_info = val
        },
        //注册后有个pictype存储证明类型
        setPicType(state, val) {
            state.picType = val
        },


    },
    getters: {
        basicInfo(state) {
            return state.finishStatus == 0 ? '/business/allBusiness/perfectOne' : '/business/allBusiness/information'
        },
        passwordPath(state) {
            return state.flat == 0 ? '/business/allBusiness/setPassword' : '/business/allBusiness/changePassword'
        },
        myBasicInfo(state) {
            return state.finishStatus == 0 ? '/business/myBusiness/perfectOne' : '/business/myBusiness/information'
        },
        welcomText(state) {
            return state.userName || state.phoneNumber;
        },
        getRuleForm(state) {
            let back = {}
            let {
                name,
                names,
                englishName = '',
                site,
                englishSite = '',
                number, //营业执照编号
                numbers, //身份证号
                person_type,
                phone,
                province,
                contact, //联系人
                city,
                legal,
                email,
                postal = 61000,
                nationality = "中国", //申请人国籍
            } = state.storeDatas;
            back["busCode"] = number;
            back["cardNum"] = numbers;
            back["rProvince"] = province;
            back["rCity"] = city;
            back["faRen"] = legal; //法人
            back["appAddCn"] = site;
            back["appAddEn"] = englishSite;
            back["appName"] = name;
            back["phone"] = phone;
            back["imgAdd"] = site;
            back["busName"] = name; //主体名称
            back["busAddress"] = site; //主体地址
            back["appNameEn"] = englishName; //英文名称
            back["appNat"] = nationality;
            back["postCode"] = postal; //邮政编码
            back["contact"] = contact; //联系人
            back["email"] = email; //联系人
            back["optype"] = 1;
            back["appliType"] = state.picType;
            back["idcardimg"] = state.id_card_info.id_card ? state.id_card_info.url : ''; //身份证正反面地址
            back["idcardface"] = state.id_card_info.url ? state.id_card_info.id_card : ''; //身份证正面地址
            back["busimg"] = state.company_card_info.url ? state.company_card_info.url : ''; //营业执照地址
            back["idcardAddress"] = state.id_card_info.url ? state.id_card_info.address : ''; //身份证住址
            return back;
        }
    },
})